// pages/insurance/insurance.js
import config from "../../config.js";
var util = require('../../utils/util.js');

const openIdUrl = config;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bgImg: "",
    agreement: "加载协议...",
    joinlist: [],
    locLatitude: 0,
    locLongitude: 0,
    page: {
      processes: [{
          'name': '用户下单',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/yhxd.png'
        },
        {
          'name': '一键呼救',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/yjfj.png'
        },
        {
          'name': '车管家到达',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/cgjdd.png'
        },
        {
          'name': '车管家严格质检',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/cgjygzj.png'
        },
        {
          'name': '车辆上门交付',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/clsmjf.png'
        },
        {
          'name': '车辆维修',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/clwx.png'
        },
        {
          'name': '车险赔付',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/clpf.png'
        },
        {
          'name': '事故协助',
          'icon': 'https://app.longchg.com/gudongcar/images/app/accident/clxz.png'
        },
      ]
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //加载背景图
    var services = wx.getStorageSync("services");
    if (services != null) {
      var service = services[1];
      console.log(service);
      this.setData({
        bgImg: service.pic
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    util.checkLocationIsOff(this)
    wx.getLocation({
      success: function(res) {
        that.setData({
          locLatitude: res.latitude,
          locLongitude: res.longitude
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  agreementDetail: function(e) {
    var id = e.currentTarget.dataset.id;
    var url = config.http + "://" + config.host + "/agreemmentContent.action?contentId=" + id;
    wx.setStorageSync("webviewUrl", url);
    wx.navigateTo({
      url: "../webview/webview"
    })
  },
  oneCall: function(e) {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: '400-9988-960',
      success: function() {
        var user = wx.getStorageSync("user");
        var houseKeeperId = user.housekeeper.keeperId;
        var orderType = 2;
        var orderFrom = 1;
        wx.request({
          url: openIdUrl.accidentAssistCall,
          data: {
            houseKeeperId: houseKeeperId,
            orderType: orderType,
            orderFrom: orderFrom,
            address: "",
            locLatitude: that.data.locLatitude,
            locLongitude: that.data.locLongitude,
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded',
            'Cookie': wx.getStorageSync("session")
          },
          success: function(res) {
            console.log(res);
            wx.hideLoading();
            if (res.data.status == 200) {


            } else {
              wx.hideLoading();
              wx.showToast({
                title: res.data.message + "",
                icon: 'none',
                mask: true,
                duration: 2000
              })
            }

          },
          error: function() {
            wx.showToast({
              title: "请求失败,请联系管理员",
              icon: 'none',
              mask: true,
              duration: 2000
            })
          }
        })
      }
    })


  },
  onPullDownRefresh: function() {
    wx.stopPullDownRefresh();
  },
})